/**
 *    @file       timer.h
 *
 *    @brief      
 *    @details
 *
 *    @version    1.0
 *    @date       02/13/2014 09:39:48 PM
 *
 *    @author     Theophilus (), wangtf418@gmail.com 
 */
#ifndef _SF_TIMER_H_
#define _SF_TIMER_H_
#include <list>
#include "srvdef.h"
#include "atomic_int.h"

struct common_timer
{
	bf_uint32_t m_timer_type;
	bf_uint32_t m_src_thd_type;
	bf_uint32_t m_src_thd_index;
	bf_uint64_t m_src_tsk_id;
};

struct interval_timer : public common_timer
{
	bf_time_t m_last_time;
	bf_time_t m_interval;
	bf_int64_t m_cyclenum;
	interval_timer()
	{
		memset(this, 0, sizeof(interval_timer));
	}
};

struct point_timer : public common_timer
{
	bf_int_t m_year;
	bf_int_t m_mon;
	bf_int_t m_day;
	bf_int_t m_hour;
	bf_int_t m_min;
	bf_int_t m_sec;
	point_timer()
	{
		memset(this, 0, sizeof(point_timer));
	}
};

class workthread;
class timer
{
public:
	timer();
	~timer();

public:
	bf_int_t add_timer(interval_timer &itimer);
	bf_int_t add_timer(point_timer &ptimer);
	bf_int_t check_interval_timer(bf_time_t curtime, std::list<common_timer> &itimers);
	bf_int_t check_point_timer(bf_tm_t &curtime, std::list<common_timer> &ptimers);

public:
	static bf_int_t add_timer(workthread *thread, interval_timer &itimer);
	static bf_int_t add_timer(workthread *thread, point_timer &ptimer);

private:
	std::list<interval_timer> m_interval_timers;
	std::list<point_timer> m_point_timers;
};

#endif

